#import "YQPBalanceModel.h"

#import "MYSheardPaymentVC.h"
#import "MYSheardPaymentParticularsVC.h"
#import "MYWithdrawVC.h"

#import "YQRealNameViewController.h"

@interface MYSheardPaymentVC ()

@property (strong, nonatomic) YQPBalanceModel *model;

@end

@implementation MYSheardPaymentVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isNavShadow = YES;
    self.navigationItem.title = kYQLS(@"分享赚钱");
    self.rightItemTitle = kYQLS(@"明细");
    [self getPresentBalanceApi];
}

#pragma mark - 分享赚钱接口
- (void)getPresentBalanceApi
{
   YQSHOWLOADINGINVIEW
    [YQPNetWorkingManager sendPostRequest:kPOST_SHARE_BALANCE_URL parameters:@{} success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        YQHIDELOADINGTIPS
        [self stopRefresh];
        if (responseObject.code == 0) {
            self.model = [YQPBalanceModel modelWithJSON:responseObject.data];

            [self.listTableView reloadData];
            
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
        
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQHIDELOADINGTIPS
        [self stopRefresh];
    }];
}

-(void)rightItemAction:(UIButton *)sender {
    MYSheardPaymentParticularsVC *VC = [[MYSheardPaymentParticularsVC alloc] init];
    kYQPUSH(VC);
}
-(void)setupView {
    [super setupView];
    self.listTableView.backgroundColor = HexColor(0xFAFAFA);
    kYQREGISTERTABLEVIEWNIBCELL(@"MYSheardPaymentHeader")
    kYQREGISTERTABLEVIEWNIBCELL(@"MYSheardPaymentWithdrawDepositCell")
    kYQREGISTERTABLEVIEWNIBCELL(@"MYSheardPaymentCountCell")
    kYQREGISTERTABLEVIEWNIBCELL(@"MYSheardPaymentVCFooterView")
    
}


#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        MYSheardPaymentHeader *header = [tableView dequeueReusableCellWithIdentifier:@"MYSheardPaymentHeader"];
        header.totalMoenyLb.text = NSStringFormat(@"HKD %@",self.model.balance);
        return header;
    }else if (indexPath.row == 1){
        MYSheardPaymentWithdrawDepositCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYSheardPaymentWithdrawDepositCell"];
        
        [cell.withdrawDepositBtn addTapAction:^(id  _Nonnull sender) {
            if (self.model.authStatus.intValue == 0) {
                YQRealNameViewController *realvc = YQRealNameViewController.new;
                kYQPUSH(realvc)

            }else if (self.model.authStatus.intValue == 2){
                kMBMesHUD(kYQLS(@"已提交认证信息"));
            }else{
                MYWithdrawVC *vc = [[MYWithdrawVC alloc] init];
                vc.balance = self.model.balance;
                kYQPUSH(vc);
            }
            
        }];
        return cell;
    }else if(indexPath.row == 4){
        MYSheardPaymentVCFooterView * footerView = [tableView dequeueReusableCellWithIdentifier:@"MYSheardPaymentVCFooterView"];
        return footerView;
    }else{
        MYSheardPaymentCountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYSheardPaymentCountCell"];
        if (indexPath.row == 2) {
            cell.titleLB.text = [NSString stringWithFormat:@"%@: %@",kYQLS(@"可提现"),self.model.balance];
        }else{
            cell.titleLB.text = [NSString stringWithFormat:@"%@: %@",kYQLS(@"待入账"),self.model.forCollection];
        }
        return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 278;
    }else if (indexPath.row == 1) {
        return 84;
    }else if (indexPath.row == 4) {
        return 135;
    }
    return 25;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.001;
}
#pragma mark - UITableViewDelegate, UITableViewDataSource end
@end
